package com.uyong.study.algorithm.sort;

/**
 * 选择排序O(n^2),原地O(1),不稳定
 * 
 * @author gonggy
 * @since 2019-01-29
 */
public class SelectSort implements ISort {

	@Override
	public void sort(int[] data) {
		if (data.length <= 1) {
			return;
		}
		for (int i = 0; i < data.length; i++) {
			int minIndex = i;
			for (int j = i + 1; j < data.length; j++) {
				if (data[j] < data[minIndex]) {
					minIndex = j;
				}
			}
			int tmp = data[i];
			data[i] = data[minIndex];
			data[minIndex] = tmp;
		}
	}
}
